namespace SmartSoft.Controls
{
    using SmartSoft;
    using SmartSoft.Invoices;
    using SmartSoft.Properties;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormLister : FormControl
    {
        private ToolStripMenuItem btnAccept;
        private ToolStripButton btnAdd;
        private ToolStripButton btnBalance;
        private ToolStripMenuItem btnCancel;
        private ToolStripButton btnClose;
        private ToolStripButton btnCopy;
        private ToolStripButton btnDelete;
        private ToolStripButton btnDesign;
        private ToolStripButton btnEdit;
        private ToolStripButton btnFilter;
        private ToolStripDropDownButton btnFunctions;
        private ToolStripButton btnHistory;
        private ToolStripMenuItem btnLock;
        private ToolStripMenuItem btnOpen;
        private ToolStripButton btnOrder;
        private ToolStripMenuItem btnPause;
        private ToolStripButton btnPayment;
        private ToolStripMenuItem btnPostGL;
        private ToolStripButton btnPreview;
        private ToolStripButton btnPrint;
        private ToolStripButton btnRefresh;
        private ToolStripButton btnVAT;
        private IContainer components;
        private GBoxControl gBoxControl1;
        private bool ib_CheckAccountingInvoice = true;
        private bool ib_MasterOrDetail = true;
        private bool ib_ShowBalanceButton;
        private bool ib_ShowOrderButton;
        private bool ib_ShowPauseButton = true;
        private bool ib_ShowPaymentButton = true;
        private string is_DetailInvoiceOrder = "";
        private string is_MasterInvoiceOrder;
        private string is_StoredProcedure = "";
        private LabelControl labelControl5;
        private LabelControl lblNotice;
        private GridControl oDetailGridBrowser;
        private SSInvoiceLib oSSInvoiceLib;
        private SSPrintInvoiceLib oSSPrintLib;
        private DataSet oLocalDetailDataSet;
        private FormEditor oLocalFormEditor;
        private FormHistoryLister oLocalFormHistoryLister;
        private DataRow oLocalMasterRow;
        private DataTable oLocalMasterTable;
        private GridControl oMasterGridBrowser;
        private PictureBox pictureBox1;
        private ToolStripSeparator tbrSep01;
        private ToolStripSeparator tbrSep02;
        private ToolStripSeparator tbrSep03;
        private ToolStripSeparator tbrSep04;
        private ToolStripSeparator tbrSep05;
        private ToolStripSeparator tbrSep06;
        private ToolStripSeparator tbrSep07;
        private ToolStripSeparator tbrSep08;
        private ToolStripSeparator tbrSep09;
        private ToolStripSeparator tbrSep10;
        private ToolStripSeparator tbrSep11;
        private ToolStripSeparator tbrSep13;
        private ToolStripSeparator tbrSep14;
        private ToolStripSeparator tbrSep15;
        private ToolStrip Toolbars;
        private ToolStripSeparator toolStripSeparator1;
        private TbarSearch txtSearch;

        public FormLister()
        {
            this.InitializeComponent();
            //if (AppInstance.Company_Ma_Th.Equals("C"))
            //{
            //    MessageBox.Show("Bạn đang chọn đơn vị tổng hợp. Không được phép vào chứng từ!", "Canh bao", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    this.Toolbars.Enabled = false;
            //}
        }

        protected void ResizeForm()
        {
            base.ResizeForm();
            //Resize screen for different resolution
            Screen scrn = Screen.FromControl(this);
            if (scrn == null)
            {
                scrn = Screen.PrimaryScreen;
            }
            int deskHeight = scrn.Bounds.Height;
            int deskWidth = scrn.Bounds.Width;
            if (deskWidth < 1000)
            {
                btnCopy.DisplayStyle = ToolStripItemDisplayStyle.Image;
                btnPayment.DisplayStyle = ToolStripItemDisplayStyle.Image;
                btnHistory.DisplayStyle = ToolStripItemDisplayStyle.Image;
            }
        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowPostInvoice)
            {
                MessageBox.Show("Không có quyền duyệt chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnPost(2);
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowAddInvoice)
            {
                MessageBox.Show("Không có quyền thêm chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                this.OnAdd();
            }
        }

        private void btnBalance_Click(object sender, EventArgs e)
        {
            if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnBalance();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowPostInvoice)
            {
                MessageBox.Show("Không có quyền huỷ chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnPost(0);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowAddInvoice)
            {
                MessageBox.Show("Không có quyền thêm chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnCopy();
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowDeleteInvoice)
            {
                MessageBox.Show("Không có quyền xóa chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnDelete();
            }
        }

        private void btnDesign_Click(object sender, EventArgs e)
        {
            this.OnDesign();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowEditInvoice)
            {
                MessageBox.Show("Không có quyền sửa chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnEdit();
            }
        }

        private void btnFilter_Click(object sender, EventArgs e)
        {
            this.OnFilter();
        }

        private void btnHistory_Click(object sender, EventArgs e)
        {
            if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnShowHistory();
            }
        }

        private void btnLock_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowLockInvoice)
            {
                MessageBox.Show("Không có quyền khóa chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnLock(true);
            }
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowLockInvoice)
            {
                MessageBox.Show("Không có quyền mở chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnLock(false);
            }
        }

        private void btnOrder_Click(object sender, EventArgs e)
        {
            if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnAddOrder();
            }
        }

        private void btnPause_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowLockInvoice)
            {
                MessageBox.Show("Không có quyền dừng chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnPause();
            }
        }

        private void btnPayment_Click(object sender, EventArgs e)
        {
            if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnPaymnet();
            }
        }

        private void btnPostGL_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowPostInvoice)
            {
                MessageBox.Show("Không có quyền cập nhật chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnPost(1);
            }
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowViewInvoice)
            {
                MessageBox.Show("Không có quyền xem, in chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnPrint(false);
            }
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowViewInvoice)
            {
                MessageBox.Show("Không có quyền xem, in chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnPrint(true);
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            this.OnRefresh();
        }

        private void btnVAT_Click(object sender, EventArgs e)
        {
            if (this.MasterGridBrowser.Rows.Count > 0)
            {
                this.OnDetailVAT();
            }
        }

        private void Detail_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if ((this.DetailGridBrowser.CurrentRow != null) && (this.DetailGridBrowser.CurrentRow.DataBoundItem != null))
            {
                DataRow row = ((DataRowView) this.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
                this.DetailInvoiceOrder = row[this.DetailKeyField].ToString();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.Toolbars = new System.Windows.Forms.ToolStrip();
            this.btnRefresh = new System.Windows.Forms.ToolStripButton();
            this.tbrSep01 = new System.Windows.Forms.ToolStripSeparator();
            this.btnFunctions = new System.Windows.Forms.ToolStripDropDownButton();
            this.btnPostGL = new System.Windows.Forms.ToolStripMenuItem();
            this.btnAccept = new System.Windows.Forms.ToolStripMenuItem();
            this.btnCancel = new System.Windows.Forms.ToolStripMenuItem();
            this.tbrSep03 = new System.Windows.Forms.ToolStripSeparator();
            this.btnPause = new System.Windows.Forms.ToolStripMenuItem();
            this.tbrSep04 = new System.Windows.Forms.ToolStripSeparator();
            this.btnLock = new System.Windows.Forms.ToolStripMenuItem();
            this.btnOpen = new System.Windows.Forms.ToolStripMenuItem();
            this.tbrSep02 = new System.Windows.Forms.ToolStripSeparator();
            this.btnAdd = new System.Windows.Forms.ToolStripButton();
            this.btnEdit = new System.Windows.Forms.ToolStripButton();
            this.btnDelete = new System.Windows.Forms.ToolStripButton();
            this.tbrSep05 = new System.Windows.Forms.ToolStripSeparator();
            this.txtSearch = new SmartSoft.Controls.TbarSearch();
            this.tbrSep06 = new System.Windows.Forms.ToolStripSeparator();
            this.btnCopy = new System.Windows.Forms.ToolStripButton();
            this.tbrSep07 = new System.Windows.Forms.ToolStripSeparator();
            this.btnPreview = new System.Windows.Forms.ToolStripButton();
            this.btnPrint = new System.Windows.Forms.ToolStripButton();
            this.tbrSep14 = new System.Windows.Forms.ToolStripSeparator();
            this.btnDesign = new System.Windows.Forms.ToolStripButton();
            this.tbrSep08 = new System.Windows.Forms.ToolStripSeparator();
            this.btnFilter = new System.Windows.Forms.ToolStripButton();
            this.tbrSep09 = new System.Windows.Forms.ToolStripSeparator();
            this.btnPayment = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.btnVAT = new System.Windows.Forms.ToolStripButton();
            this.tbrSep10 = new System.Windows.Forms.ToolStripSeparator();
            this.btnBalance = new System.Windows.Forms.ToolStripButton();
            this.tbrSep11 = new System.Windows.Forms.ToolStripSeparator();
            this.btnOrder = new System.Windows.Forms.ToolStripButton();
            this.tbrSep13 = new System.Windows.Forms.ToolStripSeparator();
            this.btnHistory = new System.Windows.Forms.ToolStripButton();
            this.tbrSep15 = new System.Windows.Forms.ToolStripSeparator();
            this.btnClose = new System.Windows.Forms.ToolStripButton();
            this.gBoxControl1 = new SmartSoft.Controls.GBoxControl();
            this.lblNotice = new SmartSoft.Controls.LabelControl();
            this.labelControl5 = new SmartSoft.Controls.LabelControl();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.Toolbars.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // Toolbars
            // 
            this.Toolbars.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnRefresh,
            this.tbrSep01,
            this.btnFunctions,
            this.tbrSep02,
            this.btnAdd,
            this.btnEdit,
            this.btnDelete,
            this.tbrSep05,
            this.txtSearch,
            this.tbrSep06,
            this.btnCopy,
            this.tbrSep07,
            this.btnPreview,
            this.btnPrint,
            this.tbrSep14,
            this.btnDesign,
            this.tbrSep08,
            this.btnFilter,
            this.tbrSep09,
            this.btnPayment,
            this.toolStripSeparator1,
            this.btnVAT,
            this.tbrSep10,
            this.btnBalance,
            this.tbrSep11,
            this.btnOrder,
            this.tbrSep13,
            this.btnHistory,
            this.tbrSep15,
            this.btnClose});
            this.Toolbars.Location = new System.Drawing.Point(0, 0);
            this.Toolbars.Name = "Toolbars";
            this.Toolbars.Size = new System.Drawing.Size(794, 25);
            this.Toolbars.TabIndex = 0;
            this.Toolbars.Text = "Toolbars";
            // 
            // btnRefresh
            // 
            this.btnRefresh.Image = global::SmartSoft.Properties.Resources.REFRESH;
            this.btnRefresh.Name = "btnRefresh";
            this.btnRefresh.Size = new System.Drawing.Size(66, 22);
            this.btnRefresh.Text = "Refresh";
            this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
            // 
            // tbrSep01
            // 
            this.tbrSep01.Name = "tbrSep01";
            this.tbrSep01.Size = new System.Drawing.Size(6, 25);
            // 
            // btnFunctions
            // 
            this.btnFunctions.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnPostGL,
            this.btnAccept,
            this.btnCancel,
            this.tbrSep03,
            this.btnPause,
            this.tbrSep04,
            this.btnLock,
            this.btnOpen});
            this.btnFunctions.Image = global::SmartSoft.Properties.Resources.FUNC;
            this.btnFunctions.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnFunctions.Name = "btnFunctions";
            this.btnFunctions.Size = new System.Drawing.Size(94, 22);
            this.btnFunctions.Text = "Chức năng";
            // 
            // btnPostGL
            // 
            this.btnPostGL.Name = "btnPostGL";
            this.btnPostGL.Size = new System.Drawing.Size(152, 22);
            this.btnPostGL.Text = "Ghi sổ";
            this.btnPostGL.Click += new System.EventHandler(this.btnPostGL_Click);
            // 
            // btnAccept
            // 
            this.btnAccept.Name = "btnAccept";
            this.btnAccept.Size = new System.Drawing.Size(152, 22);
            this.btnAccept.Text = "Duyệt";
            this.btnAccept.Click += new System.EventHandler(this.btnAccept_Click);
            // 
            // btnCancel
            // 
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(152, 22);
            this.btnCancel.Text = "Huỷ";
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // tbrSep03
            // 
            this.tbrSep03.Name = "tbrSep03";
            this.tbrSep03.Size = new System.Drawing.Size(149, 6);
            // 
            // btnPause
            // 
            this.btnPause.Name = "btnPause";
            this.btnPause.Size = new System.Drawing.Size(152, 22);
            this.btnPause.Text = "Dừng";
            this.btnPause.Visible = false;
            this.btnPause.Click += new System.EventHandler(this.btnPause_Click);
            // 
            // tbrSep04
            // 
            this.tbrSep04.Name = "tbrSep04";
            this.tbrSep04.Size = new System.Drawing.Size(149, 6);
            this.tbrSep04.Visible = false;
            // 
            // btnLock
            // 
            this.btnLock.Name = "btnLock";
            this.btnLock.Size = new System.Drawing.Size(152, 22);
            this.btnLock.Text = "Khóa";
            this.btnLock.Click += new System.EventHandler(this.btnLock_Click);
            // 
            // btnOpen
            // 
            this.btnOpen.Name = "btnOpen";
            this.btnOpen.Size = new System.Drawing.Size(152, 22);
            this.btnOpen.Text = "Mở";
            this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
            // 
            // tbrSep02
            // 
            this.tbrSep02.Name = "tbrSep02";
            this.tbrSep02.Size = new System.Drawing.Size(6, 25);
            // 
            // btnAdd
            // 
            this.btnAdd.Image = global::SmartSoft.Properties.Resources.BALANCE1;
            this.btnAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(58, 22);
            this.btnAdd.Text = "Thêm";
            this.btnAdd.ToolTipText = "Thêm mới (F2)";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnEdit
            // 
            this.btnEdit.Image = global::SmartSoft.Properties.Resources.EDIT1;
            this.btnEdit.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnEdit.Name = "btnEdit";
            this.btnEdit.Size = new System.Drawing.Size(46, 22);
            this.btnEdit.Text = "Sửa";
            this.btnEdit.ToolTipText = "Sửa (F3)";
            this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
            // 
            // btnDelete
            // 
            this.btnDelete.Image = global::SmartSoft.Properties.Resources.DELETE1;
            this.btnDelete.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new System.Drawing.Size(47, 22);
            this.btnDelete.Text = "Xóa";
            this.btnDelete.ToolTipText = "Xóa (F8)";
            this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
            // 
            // tbrSep05
            // 
            this.tbrSep05.Name = "tbrSep05";
            this.tbrSep05.Size = new System.Drawing.Size(6, 25);
            // 
            // txtSearch
            // 
            this.txtSearch.Name = "txtSearch";
            this.txtSearch.Size = new System.Drawing.Size(100, 25);
            this.txtSearch.Text = "Tìm nhanh...";
            this.txtSearch.ToolTipText = "F4";
            // 
            // tbrSep06
            // 
            this.tbrSep06.Name = "tbrSep06";
            this.tbrSep06.Size = new System.Drawing.Size(6, 25);
            // 
            // btnCopy
            // 
            this.btnCopy.Image = global::SmartSoft.Properties.Resources.COPY1;
            this.btnCopy.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnCopy.Name = "btnCopy";
            this.btnCopy.Size = new System.Drawing.Size(75, 22);
            this.btnCopy.Text = "Sao chép";
            this.btnCopy.ToolTipText = "Sao chép chứng từ (Ctrl+F2)";
            this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);
            // 
            // tbrSep07
            // 
            this.tbrSep07.Name = "tbrSep07";
            this.tbrSep07.Size = new System.Drawing.Size(6, 25);
            // 
            // btnPreview
            // 
            this.btnPreview.Image = global::SmartSoft.Properties.Resources.PREVIEW1;
            this.btnPreview.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnPreview.Name = "btnPreview";
            this.btnPreview.Size = new System.Drawing.Size(51, 22);
            this.btnPreview.Text = "Xem";
            this.btnPreview.ToolTipText = "Xem trước khi in (Ctrl+F7)";
            this.btnPreview.Click += new System.EventHandler(this.btnPreview_Click);
            // 
            // btnPrint
            // 
            this.btnPrint.Image = global::SmartSoft.Properties.Resources.PRINT2;
            this.btnPrint.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnPrint.Name = "btnPrint";
            this.btnPrint.Size = new System.Drawing.Size(37, 22);
            this.btnPrint.Text = "In";
            this.btnPrint.ToolTipText = "In (F7)";
            this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
            // 
            // tbrSep14
            // 
            this.tbrSep14.Name = "tbrSep14";
            this.tbrSep14.Size = new System.Drawing.Size(6, 25);
            // 
            // btnDesign
            // 
            this.btnDesign.Image = global::SmartSoft.Properties.Resources.DESIGN2;
            this.btnDesign.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnDesign.Name = "btnDesign";
            this.btnDesign.Size = new System.Drawing.Size(46, 22);
            this.btnDesign.Text = "Sửa";
            this.btnDesign.ToolTipText = "Sửa mẫu báo cáo (Ctrl+F3)";
            this.btnDesign.Click += new System.EventHandler(this.btnDesign_Click);
            // 
            // tbrSep08
            // 
            this.tbrSep08.Name = "tbrSep08";
            this.tbrSep08.Size = new System.Drawing.Size(6, 25);
            // 
            // btnFilter
            // 
            this.btnFilter.Image = global::SmartSoft.Properties.Resources.FILTER1;
            this.btnFilter.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnFilter.Name = "btnFilter";
            this.btnFilter.Size = new System.Drawing.Size(46, 22);
            this.btnFilter.Text = "Lọc";
            this.btnFilter.ToolTipText = "Lọc chứng từ (F9)";
            this.btnFilter.Click += new System.EventHandler(this.btnFilter_Click);
            // 
            // tbrSep09
            // 
            this.tbrSep09.Name = "tbrSep09";
            this.tbrSep09.Size = new System.Drawing.Size(6, 25);
            // 
            // btnPayment
            // 
            this.btnPayment.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnPayment.Name = "btnPayment";
            this.btnPayment.Size = new System.Drawing.Size(57, 19);
            this.btnPayment.Text = "Công nợ";
            this.btnPayment.ToolTipText = "Chi tiết thanh toán theo hóa đơn";
            this.btnPayment.Click += new System.EventHandler(this.btnPayment_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
            // 
            // btnVAT
            // 
            this.btnVAT.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnVAT.ForeColor = System.Drawing.Color.Black;
            this.btnVAT.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnVAT.Name = "btnVAT";
            this.btnVAT.Size = new System.Drawing.Size(36, 20);
            this.btnVAT.Text = "VAT";
            this.btnVAT.ToolTipText = "Khai báo hóa đơn giá trị gia tăng";
            this.btnVAT.Click += new System.EventHandler(this.btnVAT_Click);
            // 
            // tbrSep10
            // 
            this.tbrSep10.Name = "tbrSep10";
            this.tbrSep10.Size = new System.Drawing.Size(6, 38);
            // 
            // btnBalance
            // 
            this.btnBalance.Image = global::SmartSoft.Properties.Resources.BALANCE2;
            this.btnBalance.ImageTransparentColor = System.Drawing.Color.Transparent;
            this.btnBalance.Name = "btnBalance";
            this.btnBalance.Size = new System.Drawing.Size(68, 20);
            this.btnBalance.Text = "Cân đối";
            this.btnBalance.Visible = false;
            this.btnBalance.Click += new System.EventHandler(this.btnBalance_Click);
            // 
            // tbrSep11
            // 
            this.tbrSep11.Name = "tbrSep11";
            this.tbrSep11.Size = new System.Drawing.Size(6, 38);
            this.tbrSep11.Visible = false;
            // 
            // btnOrder
            // 
            this.btnOrder.Image = global::SmartSoft.Properties.Resources.ORDER;
            this.btnOrder.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnOrder.Name = "btnOrder";
            this.btnOrder.Size = new System.Drawing.Size(79, 20);
            this.btnOrder.Text = "Đơn hàng";
            this.btnOrder.Visible = false;
            this.btnOrder.Click += new System.EventHandler(this.btnOrder_Click);
            // 
            // tbrSep13
            // 
            this.tbrSep13.Name = "tbrSep13";
            this.tbrSep13.Size = new System.Drawing.Size(6, 38);
            this.tbrSep13.Visible = false;
            // 
            // btnHistory
            // 
            this.btnHistory.Image = global::SmartSoft.Properties.Resources.HISTORY;
            this.btnHistory.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnHistory.Name = "btnHistory";
            this.btnHistory.Size = new System.Drawing.Size(64, 20);
            this.btnHistory.Text = "Lịch sử";
            this.btnHistory.TextDirection = System.Windows.Forms.ToolStripTextDirection.Horizontal;
            this.btnHistory.ToolTipText = "Lịch sử chứng từ";
            this.btnHistory.Click += new System.EventHandler(this.btnHistory_Click);
            // 
            // tbrSep15
            // 
            this.tbrSep15.Name = "tbrSep15";
            this.tbrSep15.Size = new System.Drawing.Size(6, 38);
            // 
            // btnClose
            // 
            this.btnClose.Image = global::SmartSoft.Properties.Resources.CLOSE;
            this.btnClose.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(58, 20);
            this.btnClose.Text = "Thoát";
            this.btnClose.ToolTipText = "Thoát (Esc)";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // gBoxControl1
            // 
            this.gBoxControl1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.gBoxControl1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.gBoxControl1.Location = new System.Drawing.Point(-3, 504);
            this.gBoxControl1.Name = "gBoxControl1";
            this.gBoxControl1.Size = new System.Drawing.Size(799, 7);
            this.gBoxControl1.TabIndex = 11;
            this.gBoxControl1.TabStop = false;
            // 
            // lblNotice
            // 
            this.lblNotice.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lblNotice.BackColor = System.Drawing.Color.White;
            this.lblNotice.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNotice.ForeColor = System.Drawing.Color.Blue;
            this.lblNotice.Location = new System.Drawing.Point(26, 514);
            this.lblNotice.Name = "lblNotice";
            this.lblNotice.Size = new System.Drawing.Size(762, 14);
            this.lblNotice.TabIndex = 10;
            // 
            // labelControl5
            // 
            this.labelControl5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.labelControl5.BackColor = System.Drawing.Color.White;
            this.labelControl5.Font = new System.Drawing.Font("Arial", 8.25F);
            this.labelControl5.ForeColor = System.Drawing.Color.Blue;
            this.labelControl5.Location = new System.Drawing.Point(1, 511);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new System.Drawing.Size(792, 20);
            this.labelControl5.TabIndex = 9;
            // 
            // pictureBox1
            // 
            this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.pictureBox1.Image = global::SmartSoft.Properties.Resources.INFO;
            this.pictureBox1.Location = new System.Drawing.Point(10, 516);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(11, 11);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
            this.pictureBox1.TabIndex = 12;
            this.pictureBox1.TabStop = false;
            // 
            // FormLister
            // 
            this.ClientSize = new System.Drawing.Size(794, 539);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.gBoxControl1);
            this.Controls.Add(this.lblNotice);
            this.Controls.Add(this.labelControl5);
            this.Controls.Add(this.Toolbars);
            this.MinimumSize = new System.Drawing.Size(802, 566);
            this.Name = "FormLister";
            this.Toolbars.ResumeLayout(false);
            this.Toolbars.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void Master_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if ((this.MasterGridBrowser.CurrentRow != null) || (this.MasterGridBrowser.CurrentRow.DataBoundItem != null))
            {
                DataRow row = ((DataRowView) this.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                this.MasterInvoiceOrder = row[this.MasterKeyField].ToString();
            }
        }

        private void Master_DoubleClick(object sender, EventArgs e)
        {
            if (!this.SSInvoiceParameters.AllowEditInvoice)
            {
                MessageBox.Show("Không có quyền sửa chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if ((this.MasterGridBrowser.Rows.Count > 0) && this.btnEdit.Enabled)
            {
                this.OnEdit();
            }
        }

        protected virtual void OnAdd()
        {
            if ((this.SSInvoiceParameters != null) && (this.LocalFormEditor != null))
            {
                this.LocalFormEditor.LocalFormLister = this;
                this.LocalFormEditor.SSInvoiceParameters = this.SSInvoiceParameters;
                this.LocalFormEditor.LocalParentMasterRow = this.LocalParentMasterRow;
                this.LocalFormEditor.LocalMasterRow = this.LocalMasterRow;
                this.LocalFormEditor.LocalDetailDataSet = this.LocalDetailDataSet.Clone();
                if ((this.LocalDetailTable != null) && (this.LocalDetailTable.Rows.Count > 0))
                {
                    this.LocalFormEditor.LocalDetailRow = this.LocalDetailTable.Rows[0];
                }
                this.LocalFormEditor.OnAdd();
                this.LocalFormEditor.Show();
            }
        }

        protected virtual void OnAddOrder()
        {
        }

        protected virtual void OnBalance()
        {
        }

        protected virtual void OnCopy()
        {
            if (((this.SSInvoiceParameters != null) && (this.LocalFormEditor != null)) && (this.MasterGridBrowser.Rows.Count > 0))
            {
                this.LocalFormEditor.LocalFormLister = this;
                this.LocalFormEditor.SSInvoiceParameters = this.SSInvoiceParameters;
                this.LocalFormEditor.LocalParentMasterRow = this.LocalParentMasterRow;
                this.LocalFormEditor.LocalMasterRow = this.LocalMasterRow;
                this.LocalFormEditor.LocalDetailDataSet = this.LocalDetailDataSet.Copy();
                this.LocalFormEditor.OnCopy();
                this.LocalFormEditor.OnShow();
                this.LocalFormEditor.Show();
            }
        }

        protected virtual void OnDelete()
        {
        }

        protected virtual void OnDesign()
        {
            this.SSPrintLib.OnDesign(this.SSInvoiceParameters);
        }

        protected virtual void OnDetailVAT()
        {
            this.VATToolbarButton.ForeColor = this.SSInvoiceParameters.CtVAT_Status_Get(this.MasterInvoiceOrder);
        }

        protected virtual void OnEdit()
        {
            if (((this.SSInvoiceParameters != null) && (this.LocalFormEditor != null)) && (this.MasterGridBrowser.Rows.Count > 0))
            {
                this.LocalFormEditor.CheckNewRow = false;
                this.LocalFormEditor.CheckAccepted = false;
                this.LocalFormEditor.LocalFormLister = this;
                this.LocalFormEditor.SSInvoiceParameters = this.SSInvoiceParameters;
                this.LocalFormEditor.SavedMasterOrder = this.MasterInvoiceOrder;
                this.LocalFormEditor.LocalParentMasterRow = this.LocalParentMasterRow;
                this.LocalFormEditor.LocalMasterRow = this.LocalMasterRow;
                this.LocalFormEditor.LocalDetailDataSet = this.LocalDetailDataSet.Copy();
                this.LocalFormEditor.OnShow();
                this.LocalFormEditor.Show();
            }
        }

        protected virtual void OnFillData()
        {
        }

        protected virtual void OnFilter()
        {
            this.OnFillData();
            this.MasterGridBrowser.DataSource = new BindingSource(this.LocalMasterTable, this.LocalMasterTable.TableName);
            ((BindingSource) this.MasterGridBrowser.DataSource).Sort = this.MasterOrderString;
            if (this.LocalMasterTable.Rows.Count <= 0)
            {
                this.MasterInvoiceOrder = "SSSOFT2009";
            }
        }

        protected virtual void OnLock(bool pb_Locked)
        {
        }

        protected virtual void OnPause()
        {
        }

        protected virtual void OnPaymnet()
        {
            //new FormPaymentDetail(this.SSInvoiceParameters, this.MasterInvoiceOrder).Show();
        }

        protected virtual void OnPost(int pi_Posted)
        {
        }

        private void OnPrint(bool pb_Printed)
        {
            if (this.SSInvoiceParameters.HistoryType == "K")
            {
                this.SSPrintLib.OnCTKTPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "M")
            {
                this.SSPrintLib.OnCTMHPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "B")
            {
                this.SSPrintLib.OnCTBHPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "Q")
            {
                this.SSPrintLib.OnCTBGPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "D")
            {
                this.SSPrintLib.OnCTDHPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "N")
            {
                this.SSPrintLib.OnCTNXPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "Y")
            {
                this.SSPrintLib.OnCTYCMPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "W")
            {
                this.SSPrintLib.OnCTKHOPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "L")
            {
                this.SSPrintLib.OnCTKHOPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "G")
            {
                this.SSPrintLib.OnCTKHOPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "C")
            {
                this.SSPrintLib.OnCTKHOPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "X")
            {
                this.SSPrintLib.OnCTKHOPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "H")
            {
                this.SSPrintLib.OnCTKHOPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }         
            else if (this.SSInvoiceParameters.HistoryType == "P")
            {
                this.SSPrintLib.OnCTTPPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "S")
            {
                this.SSPrintLib.OnCTSXPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "O")
            {
                this.SSPrintLib.OnCTNBPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.SSInvoiceParameters.HistoryType == "T")
            {
                this.SSPrintLib.OnCTYCMPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
                
                //this.SSPrintLib.OnCTVATPrint(pb_Printed, this.SSInvoiceParameters, this.LocalMasterRow);
            }
        }

        protected virtual void OnRefresh()
        {
            this.OnFillData();
            this.MasterGridBrowser.DataSource = new BindingSource(this.LocalMasterTable, this.LocalMasterTable.TableName);
            ((BindingSource) this.MasterGridBrowser.DataSource).Sort = this.MasterOrderString;
            if (this.LocalMasterTable.Rows.Count <= 0)
            {
                this.MasterInvoiceOrder = "SSSOFT2009";
            }
        }

        internal virtual void OnResetControls()
        {
            this.MasterGridBrowser.SetColumnWidths();
            this.DetailGridBrowser.SetColumnWidths();
        }

        private void OnResetInvoideNumber()
        {
            if (!this.SSInvoiceParameters.AllowPostInvoice || !this.SSInvoiceParameters.AllowLockInvoice)
            {
                MessageBox.Show("Không có quyền đánh lại số chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (!string.IsNullOrEmpty(this.StoredProcedure) && (MessageBox.Show("Bạn thực sự muốn đánh lại số chứng từ không?", AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No))
            {
                FormResetInvoiceOrder order = new FormResetInvoiceOrder();
                order.ShowDialog();
                if (order.CheckAccepted)
                {
                    this.SSInvoiceParameters.SSInvoiceMethod.ResetInvoiceNumber(this.StoredProcedure, AppInstance.Subsidiary, this.InvoiceCode, order.StartDate, order.EndDate, order.NumberFormat, order.StartNumber);
                    this.OnRefresh();
                    MessageBox.Show(AppInstance.EndMessage, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }

        internal virtual void OnSetPosition(string ps_MasterInvoiceOrder)
        {
            this.is_MasterInvoiceOrder = ps_MasterInvoiceOrder;
            BindingSource dataSource = this.MasterGridBrowser.DataSource as BindingSource;
            dataSource.Position = dataSource.Find(this.MasterKeyField, this.MasterInvoiceOrder);
            this.OnShowMaster();
        }

        internal virtual void OnShowDetail()
        {
        }

        internal virtual void OnShowDetailNotice()
        {
        }

        protected virtual void OnShowHistory()
        {
            new FormHistoryLister(this.SSInvoiceParameters, this.MasterInvoiceOrder).Show();
        }

        internal virtual void OnShowMaster()
        {
            if (this.DetailGridBrowser != null)
            {
                this.DetailGridBrowser.DataSource = new BindingSource(this.LocalDetailDataSet, this.LocalDetailTable.TableName);
                ((BindingSource) this.oDetailGridBrowser.DataSource).Sort = this.DetailOrderString;
                if (this.VATToolbarButton.Visible)
                {
                    this.VATToolbarButton.ForeColor = this.SSInvoiceParameters.CtVAT_Status_Get(this.MasterInvoiceOrder);
                }
            }
        }

        internal virtual void OnShowMasterNotice()
        {
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case Keys.F2:
                    if (this.SSInvoiceParameters.AllowAddInvoice)
                    {
                        if (this.btnAdd.Enabled)
                        {
                            this.OnAdd();
                        }
                        break;
                    }
                    MessageBox.Show("Không có quyền thêm chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    break;

                case Keys.F3:
                    if (this.SSInvoiceParameters.AllowEditInvoice)
                    {
                        if ((this.MasterGridBrowser.Rows.Count > 0) && this.btnEdit.Enabled)
                        {
                            this.OnEdit();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Không có quyền sửa chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    return true;

                case Keys.F4:
                    this.txtSearch.Focus();
                    return true;

                case Keys.F7:
                    if (this.SSInvoiceParameters.AllowViewInvoice)
                    {
                        if ((this.MasterGridBrowser.Rows.Count > 0) && this.btnPreview.Enabled)
                        {
                            this.OnPrint(true);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Không có quyền xem, in chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    return true;

                case Keys.F8:
                    if (this.SSInvoiceParameters.AllowDeleteInvoice)
                    {
                        if ((this.MasterGridBrowser.Rows.Count > 0) && this.btnDelete.Enabled)
                        {
                            this.OnDelete();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Không có quyền xóa chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    return true;

                case Keys.F9:
                    if (this.btnFilter.Enabled)
                    {
                        this.OnFilter();
                    }
                    return true;

                case Keys.Escape:
                    base.Close();
                    return true;

                case (Keys.Control | Keys.F2):
                    if (this.SSInvoiceParameters.AllowAddInvoice)
                    {
                        if ((this.MasterGridBrowser.Rows.Count > 0) && this.btnCopy.Enabled)
                        {
                            this.OnCopy();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Không có quyền thêm chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    return true;

                case (Keys.Control | Keys.F3):
                    if (this.btnDesign.Enabled)
                    {
                        this.OnDesign();
                    }
                    return true;

                case (Keys.Control | Keys.F7):
                    if (this.SSInvoiceParameters.AllowViewInvoice)
                    {
                        if ((this.MasterGridBrowser.Rows.Count > 0) && this.btnPreview.Enabled)
                        {
                            this.OnPrint(false);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Không có quyền xem, in chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    return true;

                case (Keys.Control | Keys.F9):
                    this.OnResetInvoideNumber();
                    return true;

                default:
                    return base.ProcessCmdKey(ref msg, keyData);
            }
            return true;
        }

        [Category("Lister properties"), DefaultValue(true), Description("Indicating that the invoice is accounting invoice or others.")]
        public bool CheckAccountingInvoice
        {
            get
            {
                return this.ib_CheckAccountingInvoice;
            }
            set
            {
                this.ib_CheckAccountingInvoice = value;
                this.btnPostGL.Visible = this.CheckAccountingInvoice;
                this.btnPause.Visible = !this.CheckAccountingInvoice;
                this.tbrSep04.Visible = !this.CheckAccountingInvoice;
                if (!this.CheckAccountingInvoice)
                {
                    this.ShowPaymentButton = false;
                }
            }
        }

        [Browsable(false), Description("The datagridview to show detail invoice."), Category("Lister properties")]
        public GridControl DetailGridBrowser
        {
            get
            {
                return this.oDetailGridBrowser;
            }
            set
            {
                if (this.oDetailGridBrowser != value)
                {
                    this.oDetailGridBrowser = value;
                    this.oDetailGridBrowser.AutoGenerateColumns = false;
                    this.oDetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.Detail_CellEnter);
                }
            }
        }

        [DefaultValue(""), Category("Lister properties"), Description("The current row detail to edit or add."), Browsable(false)]
        public string DetailInvoiceOrder
        {
            get
            {
                return this.is_DetailInvoiceOrder;
            }
            set
            {
                bool flag = this.is_DetailInvoiceOrder == value;
                this.is_DetailInvoiceOrder = value;
                if ((!this.MasterOrDetail && !flag) || (this.MasterOrDetail && flag))
                {
                    this.OnShowDetailNotice();
                }
                if (flag)
                {
                    this.OnShowDetail();
                }
                this.MasterOrDetail = false;
            }
        }

        [DefaultValue("Stt0"), Category("Lister properties"), Description("The detail primary key field name.")]
        public string DetailKeyField
        {
            get
            {
                if (this.SSInvoiceParameters == null)
                {
                    return "";
                }
                return this.SSInvoiceParameters.DetailKeyField;
            }
            set
            {
                if (this.SSInvoiceParameters != null)
                {
                    this.SSInvoiceParameters.DetailKeyField = value;
                }
            }
        }

        [Description("The detail order string."), DefaultValue("Stt_Nv"), Category("Lister properties")]
        public string DetailOrderString
        {
            get
            {
                return this.SSInvoiceParameters.DetailOrderString;
            }
            set
            {
                if (this.SSInvoiceParameters != null)
                {
                    this.SSInvoiceParameters.DetailOrderString = value;
                }
            }
        }

        [Category("Lister properties"), Description("The parameters that declare by system, user, invoice code."), DefaultValue((string) null), Browsable(false)]
        public SSInvoiceLib SSInvoiceParameters
        {
            get
            {
                if (this.oSSInvoiceLib == null)
                {
                    this.SSInvoiceParameters = new SSInvoiceLib();
                }
                return this.oSSInvoiceLib;
            }
            set
            {
                this.oSSInvoiceLib = value;
            }
        }

        [Description("The parameters that declare by system, user, invoice code."), Category("Lister properties"), DefaultValue((string) null), Browsable(false)]
        public SSPrintInvoiceLib SSPrintLib
        {
            get
            {
                if (this.oSSPrintLib == null)
                {
                    this.oSSPrintLib = new SSPrintInvoiceLib();
                }
                return this.oSSPrintLib;
            }
            set
            {
                this.oSSPrintLib = value;
            }
        }

        [DefaultValue(""), Category("Lister properties"), Browsable(false), Description("The current invoice code to edit or add.")]
        public string InvoiceCode
        {
            get
            {
                if (this.SSInvoiceParameters == null)
                {
                    return "";
                }
                return this.SSInvoiceParameters.InvoiceCode;
            }
            set
            {
                if (this.SSInvoiceParameters != null)
                {
                    this.SSInvoiceParameters.InvoiceCode = value;
                    if (!string.IsNullOrEmpty(this.SSInvoiceParameters.InvoiceCode))
                    {
                        this.Text = this.SSInvoiceParameters.InvoiceName;
                        this.OnFillData();
                    }
                }
            }
        }

        [Browsable(false), DefaultValue((string) null), Category("Lister properties"), Description("The detail dataset.")]
        public DataSet LocalDetailDataSet
        {
            get
            {
                return this.oLocalDetailDataSet;
            }
            set
            {
                this.oLocalDetailDataSet = value;
            }
        }

        [Browsable(false), Category("Lister properties"), DefaultValue((string) null), Description("The detail table.")]
        public DataTable LocalDetailTable
        {
            get
            {
                return this.LocalDetailDataSet.Tables[0];
            }
        }

        [Browsable(false), Category("Lister properties"), Description("The editor form."), DefaultValue((string) null)]
        public FormEditor LocalFormEditor
        {
            get
            {
                return this.oLocalFormEditor;
            }
            set
            {
                this.oLocalFormEditor = value;
            }
        }

        [Description("The history lister form."), Browsable(false), DefaultValue((string) null), Category("Lister properties")]
        public FormHistoryLister LocalFormHistoryLister
        {
            get
            {
                return this.oLocalFormHistoryLister;
            }
            set
            {
                this.oLocalFormHistoryLister = value;
            }
        }

        [Category("Lister properties"), DefaultValue((string) null), Browsable(false), Description("The master row.")]
        public DataRow LocalMasterRow
        {
            get
            {
                if (this.oLocalMasterRow == null)
                {
                    this.MasterInvoiceOrder = "SSSOFT2009";
                }
                return this.oLocalMasterRow;
            }
            set
            {
                this.oLocalMasterRow = value;
            }
        }

        [DefaultValue((string) null), Browsable(false), Category("Lister properties"), Description("The master Table.")]
        public DataTable LocalMasterTable
        {
            get
            {
                return this.oLocalMasterTable;
            }
            set
            {
                this.oLocalMasterTable = value;
            }
        }

        [Category("Lister properties"), Browsable(false), Description("The parent master datarow.")]
        public DataRow LocalParentMasterRow
        {
            get
            {
                if ((this.MasterGridBrowser.CurrentRow != null) && (this.MasterGridBrowser.CurrentRow.DataBoundItem != null))
                {
                    return ((DataRowView) this.MasterGridBrowser.CurrentRow.DataBoundItem).Row;
                }
                return this.LocalMasterTable.NewRow();
            }
        }

        [Browsable(false), Category("Lister properties"), Description("The datagridview to show master invoice.")]
        public GridControl MasterGridBrowser
        {
            get
            {
                return this.oMasterGridBrowser;
            }
            set
            {
                if (this.oMasterGridBrowser != value)
                {
                    this.oMasterGridBrowser = value;
                    this.oMasterGridBrowser.AutoGenerateColumns = false;
                    this.oMasterGridBrowser.DataSource = new BindingSource(this.LocalMasterTable, this.LocalMasterTable.TableName);
                    ((BindingSource) this.oMasterGridBrowser.DataSource).Sort = this.MasterOrderString;
                    this.oMasterGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.Master_CellEnter);
                    this.oMasterGridBrowser.DoubleClick += new EventHandler(this.Master_DoubleClick);
                }
            }
        }

        [Browsable(false), Category("Lister properties"), Description("The current invoice order to edit or add."), DefaultValue("")]
        public string MasterInvoiceOrder
        {
            get
            {
                return this.is_MasterInvoiceOrder;
            }
            set
            {
                if (SSDataAccess.CheckConnected)
                {
                    if ((this.is_MasterInvoiceOrder != value) && !string.IsNullOrEmpty(value))
                    {
                        this.MasterOrDetail = false;
                        this.is_MasterInvoiceOrder = value;
                        this.OnShowMaster();
                    }
                    if (!this.MasterOrDetail && (this.LocalMasterRow.RowState != DataRowState.Detached))
                    {
                        this.OnShowMasterNotice();
                    }
                    this.MasterOrDetail = true;
                }
            }
        }

        [Category("Lister properties"), DefaultValue("Stt"), Description("The master primary key field name.")]
        public string MasterKeyField
        {
            get
            {
                if (this.SSInvoiceParameters == null)
                {
                    return "";
                }
                return this.SSInvoiceParameters.MasterKeyField;
            }
            set
            {
                if (this.SSInvoiceParameters != null)
                {
                    this.SSInvoiceParameters.MasterKeyField = value;
                }
            }
        }

        [DefaultValue("Ngay_Ct, So_Ct"), Description("The master order string."), Category("Lister properties")]
        public string MasterOrderString
        {
            get
            {
                return this.SSInvoiceParameters.MasterOrderString;
            }
            set
            {
                if (this.SSInvoiceParameters != null)
                {
                    this.SSInvoiceParameters.MasterOrderString = value;
                }
            }
        }

        [Browsable(false), Category("Lister properties"), DefaultValue(true), Description("Indicate that we are on the master grid or detail grid.")]
        public bool MasterOrDetail
        {
            get
            {
                return this.ib_MasterOrDetail;
            }
            set
            {
                if (this.ib_MasterOrDetail != value)
                {
                    this.ib_MasterOrDetail = value;
                }
            }
        }

        [DefaultValue(false), Description("Get or set balanace button visible or invisible."), Category("Lister properties")]
        public bool ShowBalanceButton
        {
            get
            {
                return this.ib_ShowBalanceButton;
            }
            set
            {
                this.ib_ShowBalanceButton = value;
                this.btnBalance.Visible = this.ShowBalanceButton;
                this.tbrSep11.Visible = this.ShowBalanceButton;
            }
        }

        [DefaultValue(false), Category("Lister properties"), Description("Get or set order button visible or invisible.")]
        public bool ShowOrderButton
        {
            get
            {
                return this.ib_ShowOrderButton;
            }
            set
            {
                this.ib_ShowOrderButton = value;
                this.btnOrder.Visible = this.ShowOrderButton;
                this.tbrSep13.Visible = this.ShowOrderButton;
            }
        }

        [DefaultValue(true), Description("Indicating that the pause button is shown or not."), Category("Lister properties")]
        public bool ShowPauseButton
        {
            get
            {
                return this.ib_ShowPauseButton;
            }
            set
            {
                this.ib_ShowPauseButton = value;
                this.btnPause.Visible = this.ShowPauseButton;
                this.tbrSep03.Visible = this.ShowPauseButton;
            }
        }

        [DefaultValue(true), Description("Indicating that the invoice is accounting invoice or others."), Category("Lister properties")]
        public bool ShowPaymentButton
        {
            get
            {
                return this.ib_ShowPaymentButton;
            }
            set
            {
                this.ib_ShowPaymentButton = value;
                this.btnPayment.Visible = this.ShowPaymentButton;
                this.btnVAT.Visible = this.ShowPaymentButton;
                this.tbrSep10.Visible = this.ShowPaymentButton;
            }
        }

        [Category("Lister properties"), DefaultValue(""), Description("The stored procedure name to change invoice number.")]
        public string StoredProcedure
        {
            get
            {
                return this.is_StoredProcedure;
            }
            set
            {
                this.is_StoredProcedure = value;
            }
        }

        public ToolStripButton VATToolbarButton
        {
            get
            {
                return this.btnVAT;
            }
        }

        [Browsable(false), Description("The warning message."), Category("Lister properties")]
        public string WarningMessage
        {
            set
            {
                this.lblNotice.Text = value;
            }
        }
    }
}

